package com.cloudcc.mobile.adapter;

import java.lang.reflect.Field;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudcc.cloudframe.adapter.CommonAdapter;
import com.cloudcc.cloudframe.adapter.ViewHolder;
import com.cloudcc.cloudframe.model.MenuTabModel;
import com.cloudcc.mobile.R;

/** 
* @Description: 主页九宫格的适配器 
* @author wangzhiqiang
* @date 2015-10-27 下午2:39:40 
*  
*/
public class MainFunListAdapter extends CommonAdapter<MenuTabModel> {
	public MainFunListAdapter(Context mContext) {
		super(mContext);
	}

	@Override
	public void convert(ViewHolder holder,
			MenuTabModel t) {

		ImageView bg = holder.getView(R.id.menu_image_bg);
		ImageView icon = holder.getView(R.id.menu_add_icon);
		TextView name = holder.getView(R.id.menu_add_name);

		name.setText(t.tab_name);
		try {
			Class drawable = R.drawable.class;
			Field field = drawable.getField(t.imageId);
			int id = field.getInt(field.getName());
			icon.setImageBitmap(null);
			icon.setBackgroundResource(id);

			String bgid = "add" + (holder.getPostion() % 10);
			Field field2 = drawable.getField(bgid);
			int bg_id = field2.getInt(field2.getName());
			bg.setImageBitmap(null);
			bg.setBackgroundResource(bg_id);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public int getLayoutId() {
		return R.layout.menu_add_item;
	}
}
